﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LPV_POS.Module;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_so_Ban_Gia_Mo : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture; 
        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                bton_thoat_2.Text = rm.GetString("thoat", culture);
                bton_chon_2.Text = rm.GetString("dongy", culture);
                btnXoa.Text = rm.GetString("xoa", culture);
                this.Name = rm.GetString("bangiamo", culture);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion
        public mh_so_Ban_Gia_Mo(string _TieuDe, string _NoiDung, string _btnPhanTram_Text)
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            
            if (_TieuDe != "")
                this.Text = _TieuDe;
                   
            int iso = 0;
            int.TryParse(_NoiDung.Replace("-",""), out iso);
            txt_ketqua.Text = iso.ToString("N0");
            btnPhanTram.Text = _btnPhanTram_Text;
            if (_NoiDung.IndexOf("-") == 0)
                lblPhanTram.Text = "-";
        }

        public mh_so_Ban_Gia_Mo(string _TieuDe, string _NoiDung, string _btnPhanTram_Text, Chon _oChon)
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            if (_TieuDe != "")
                this.Text = _TieuDe;
            int iso = 0;
            int.TryParse(_NoiDung, out iso);
            txt_ketqua.Text = iso.ToString("N0");
            btnPhanTram.Text = _btnPhanTram_Text;
            if (_oChon == Chon.Phan_Tram)
                this.button1_Click_1(btnPhanTram, null);
        }

        public enum Chon
        {
            Phan_Tram,
            Tien
        }
        
        #region cac su kien
        private void bton_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }     

        private void mh_so_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

         
        }

        private void bton_0_Click(object sender, EventArgs e)
        {
            try
            {
                DevExpress.XtraEditors.SimpleButton btn = (DevExpress.XtraEditors.SimpleButton)sender;

                if (txt_ketqua.SelectedText == txt_ketqua.Text)
                    txt_ketqua.Text = btn.Text;
                else if (txt_ketqua.SelectedText.Trim() != "")
                    txt_ketqua.SelectedText = btn.Text;
                else
                    txt_ketqua.Text += btn.Text;
                txt_ketqua.Text = int.Parse(txt_ketqua.Text.Replace(",", "")).ToString("N0");
            }
            catch
            {
            }
        }
                

        private void bton_xoa_Click(object sender, EventArgs e)
        {
            if (txt_ketqua.Text != "" && txt_ketqua.Text != "0")
            {
                txt_ketqua.Text = txt_ketqua.Text.Substring(0, txt_ketqua.Text.Length - 1);
                if (txt_ketqua.Text == "")
                    txt_ketqua.Text = "0";
                txt_ketqua.Text = int.Parse(txt_ketqua.Text.Replace(",", "")).ToString("N0");

                
            }

        }

        private void txt_ketqua_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void bton_chon_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (txt_ketqua.Text != "")
                    this.DialogResult = DialogResult.OK;                    
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Vui lòng nhập số", loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            this.Close();
        }
        #endregion

        private void bton_thoat_2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (txt_ketqua.Text != "")
                {
                    this.DialogResult = DialogResult.OK;
                    return;

                }
                else
                {
                    Mod_messagebox mess = new Mod_messagebox();
                    mess.messagebox_pos("Thông báo", "Vui lòng nhập số", loaithongbao.canhbao.GetHashCode());
                    return;
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            txt_ketqua.Text = "0";
        }

        public object ShowForm()
        {
            object iso = 0;
            try
            {
                this.ShowDialog();
                //int.TryParse(txt_ketqua.Text.Trim().Replace(",",""), out iso);
                if (txt_ketqua.Text == "")
                    txt_ketqua.Text = "0";
                if (lblPhanTram.Text == "%")
                    iso = txt_ketqua.Text.Trim().Replace(",", "") + lblPhanTram.Text;
                else if (lblPhanTram.Text == "-")
                    iso = lblPhanTram.Text + txt_ketqua.Text.Trim().Replace(",", "");
                else
                    iso = txt_ketqua.Text.Trim().Replace(",", "");
            }
            catch
            {

            }
            return iso;
        }

        private void btndCard_Click(object sender, EventArgs e)
        {
            int itien = 0;
            int.TryParse(txt_ketqua.Text.Replace(",", ""), out itien);
            txt_ketqua.Text = (itien + 100000).ToString("N0");
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (lblPhanTram.Text == "")
                lblPhanTram.Text = ((System.Windows.Forms.Control)(sender)).Text;
            else
                lblPhanTram.Text = "";

        }
    }
}